#include "UserConfig.h"

UserConfig::UserConfig(const wxString& filePath)
{
    fileConfig = 
		new wxFileConfig(wxEmptyString, wxEmptyString, filePath, wxEmptyString, wxCONFIG_USE_LOCAL_FILE|wxCONFIG_USE_RELATIVE_PATH);
}

 UserConfig::~UserConfig()
 {
    delete fileConfig;
 }

bool  UserConfig::ReadBool(const wxString& name)
{
    bool b = false;
    fileConfig->Read(name, &b);
    return b;
}


wxString UserConfig::GetPassport()
{
    //return fileConfig->Read(_T("passport"), wxEmptyString);
    return fileConfig->Read(_T("passport"), wxEmptyString);
}

void UserConfig::SetPassport(const wxString& passport)
{
    fileConfig->Write(_T("passport"), passport);
    //fileConfig->Write(_T("passport"), passport);
}

wxString UserConfig::GetDisplayName()
{
	return fileConfig->Read(_T("displayName"), wxEmptyString);
}

void UserConfig::SetDisplayName(const wxString& value)
{
	fileConfig->Write(_T("displayName"), value);
	fileConfig->Flush();
}

wxString UserConfig::GetPersonalMessage()
{
	return fileConfig->Read(_T("personalMessage"), wxEmptyString);
}

void UserConfig::SetPersonalMessage(const wxString& value)
{
	fileConfig->Write(_T("personalMessage"), value);
	fileConfig->Flush();
}

wxString UserConfig::GetDisplayPicture()
{
	return fileConfig->Read(_T("displayPicture"), wxEmptyString);
}

void UserConfig::SetDisplayPicture(const wxString& value)
{
	fileConfig->Write(_T("displayPicture"), value);
	fileConfig->Flush();
}

wxString UserConfig::GetContactVersion()
{
	return fileConfig->Read(_T("contactVersion"), _T("0 0"));
}

void UserConfig::SetContactVersion(const wxString& version)
{
	fileConfig->Write(_T("contactVersion"), version);
	fileConfig->Flush();
}


wxColor UserConfig::GetMessageColor()
{
    return wxColour(fileConfig->Read(_T("color.red"), (long)0),
                    fileConfig->Read(_T("color.green"), (long)0),
                    fileConfig->Read(_T("color.blue"), (long)0));
}

void UserConfig::SetMessageColor(const wxColor& color)
{
    fileConfig->Write(_T("color.red"), color.Red());
    fileConfig->Write(_T("color.green"), color.Green());
    fileConfig->Write(_T("color.blue"), color.Blue());
    fileConfig->Flush();
}

wxFont UserConfig::GetMessageFont()
{
    int size = fileConfig->Read(_T("font.size"), wxNORMAL_FONT->GetPointSize());
    int style = fileConfig->Read(_T("font.style"), wxFONTSTYLE_NORMAL);
    wxFontWeight weight = (wxFontWeight)fileConfig->Read(_T("font.weight"),wxFONTWEIGHT_NORMAL);
    bool underline = false;
    wxString fontname = fileConfig->Read(_T("font.name"));
    return wxFont(size, wxFONTFAMILY_DEFAULT, style, weight, underline, fontname);
}

void UserConfig::SetMessageFont(const wxFont& font)
{
    fileConfig->Write(_T("font.name"), font.GetFaceName());
    fileConfig->Write(_T("font.size"), font.GetPointSize());
    fileConfig->Write(_T("font.style"), font.GetStyle());
    fileConfig->Write(_T("font.weight"), font.GetWeight());
    fileConfig->Flush();
}

bool UserConfig::GetShowNewLine()
{
	return ReadBool(_T("showNewLine"));
}

void UserConfig::SetShowNewLine(bool value)
{
    fileConfig->Write(_T("showNewLine"), value);
    fileConfig->Flush();
}

bool UserConfig::GetShowTimeStamp()
{
	return ReadBool(_T("showTimeStamp"));
}
void UserConfig::SetShowTimeStamp(bool value)
{
    fileConfig->Write(_T("showTimeStamp"), value);
    fileConfig->Flush();
}

bool UserConfig::GetMessageShiftEnter()
{
	return ReadBool(_T("messageShiftEnter"));
}

void UserConfig::SetMessageShiftEnter(bool value)
{
	fileConfig->Write(_T("messageShiftEnter"), value);
    fileConfig->Flush();
}

bool UserConfig::GetKeepHistory()
{
	return ReadBool(_T("keepHistory"));
}

void UserConfig::SetKeepHistory(bool value)
{
    fileConfig->Write(_T("keepHistory"), value);
    fileConfig->Flush();
}

wxString UserConfig::GetHistoryFolder()
{
	return fileConfig->Read(_T("historyFolder"), wxEmptyString);
}

void UserConfig::SetHistoryFolder(const wxString& value)
{
    fileConfig->Write(_T("historyFolder"), value);
    fileConfig->Flush();
}

wxString UserConfig::GetFileTransferFolder()
{
	return fileConfig->Read(_T("fileTransferFolder"), wxEmptyString);
}

void UserConfig::SetFileTransferFolder(const wxString& value)
{
	fileConfig->Write(_T("fileTransferFolder"), value);
    fileConfig->Flush();
}

bool UserConfig::GetShowAlerts()
{
	return ReadBool(_T("showAlerts"));
}

void UserConfig::SetShowAlerts(bool value)
{
    fileConfig->Write(_T("showAlerts"), value);
    fileConfig->Flush();
}
